package com.erytech.linktalk.web.client.dataview;

import com.erytech.linktalk.web.client.datasource.SmileyDataSource;
import com.erytech.linktalk.web.client.framework.DataUpdateEvent;
import com.erytech.linktalk.web.client.framework.PopupDataView;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.SourcesTableEvents;
import com.google.gwt.user.client.ui.TableListener;

public class SmileyView extends PopupDataView {

	private FlexTable iconsTable = new FlexTable();
	
	public SmileyView(SmileyDataSource dataSource) {
		super(dataSource);
		initView();
	}

	private void initView() {
		setStyleName("smiley-view");
		for(int row = 0; row < getSmileyDataSource().getRowCount(); row++) {
			for (int col = 0; col < getSmileyDataSource().getColCount(); col++) {
				iconsTable.setWidget(row, col, getSmileyDataSource().getSmiley(row, col));
			}
		} 
		iconsTable.addTableListener(new TableListener() {
			public void onCellClicked(SourcesTableEvents sender, int row, int col) {
				SmileyView.this.hide();
				getSmileyDataSource().setSelected(row, col);
			}
		});
		add(iconsTable);
	}

	public void onDataUpdateEvent(DataUpdateEvent event) {
		//nothing todo.
	}

	private SmileyDataSource getSmileyDataSource() {
		return (SmileyDataSource) getDataSource();
	}
}